package com.alibaba.travel.comment.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.travel.comment.dto.CommentDto;
import com.alibaba.travel.common.utils.PageUtils;
import com.alibaba.travel.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.alibaba.travel.comment.dto.entity.CommentEntity;
import com.alibaba.travel.comment.service.CommentService;


/**
 * 评论表
 *
 * @author wherezy
 * @email wherezy@tom.com
 * @date 2023-02-23 15:11:41
 */
@Api(tags = {"评论表CommentController"})
@RestController
@RequestMapping("comment/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 查询所有评论
     */
    @ApiOperation(value="查询所有评论以及子评论", notes="")
    @PostMapping("/queryAll")
    public R queryAll(@RequestBody Map<String, Object> params){
        PageUtils page = commentService.queryAll(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @ApiOperation(value="分页获取信息", notes="k-v map形式封装分页参数")
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = commentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value="获取信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CommentEntity comment = commentService.getById(id);

        return R.ok().put("comment", comment);
    }

    /**
     * 保存
     */
    @ApiOperation(value="保存")
    @PostMapping("/save")
    public R save(@RequestBody CommentDto comment){
		commentService.save(comment);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public R update(@RequestBody CommentEntity comment){
		commentService.updateById(comment);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		commentService.deleteByIds(Arrays.asList(ids));

        return R.ok();
    }

}
